<template>
  <div class="menu">
    <el-container>
      <el-header>
        <div class="hl">万云医疗管理系统</div>
        <!-- 个人管理 -->
        <div class="hr">
          <el-dropdown trigger="click">
            <span class="el-dropdown-link">
              <el-avatar size="medium" :src="userinfo.avatar"></el-avatar>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item icon="el-icon-user">
                {{ userinfo.username }}
              </el-dropdown-item>
              <el-dropdown-item icon="el-icon-s-check">
                {{ userinfo.role_name }}
              </el-dropdown-item>
              <el-dropdown-item
                @click.native="$router.push('/my')"
                icon="el-icon-setting"
              >
                用户设置
              </el-dropdown-item>
              <el-dropdown-item
                @click.native="logout()"
                icon="el-icon-switch-button"
              >
                退出登录
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>

      <!-- 选择菜单-->
      <el-container>
        <el-aside width="200px">
          <el-menu
            default-active="cutpath"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            :unique-opened="true"
          >
            <el-submenu :index="v.path" v-for="(v, k) in menu" :key="v.path">
              <template slot="title">
                <el-badge
                  :value="v.path == 'ass' ? $store.state.notwriteassnum : ''"
                  class="items"
                >
                  <i :class="icon[k]"></i>
                  <span>{{ v.name }}</span>
                </el-badge>
              </template>
              <el-menu-item-group v-for="i in v.children" :key="i.path">
                <el-menu-item :index="i.path" @click="tab('/menu/' + i.path)">
                  <el-badge
                    :value="
                      i.path == 'myass' ? $store.state.notwriteassnum : ''
                    "
                    class="items"
                  >
                    <i class="el-icon-paperclip"></i> {{ i.name }}
                  </el-badge>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>

        <!-- 内容展示 -->
        <el-main style="padding: 0">
          <div class="content">
            <div class="item">
              <br />
              <router-view></router-view>
            </div>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      menu: [], //菜单数据
      cutpath: "selobs",
      icon: [
        //图标
        "el-icon-view",
        "el-icon-c-scale-to-original",
        "el-icon-tickets",
        "el-icon-bangzhu",
        "el-icon-pie-chart",
      ],
      userinfo:
        "../assets/u=1812368020,115607582&fm=253&fmt=auto&app=138&f=JPEG.webp", //图片路径
    };
  },
  mounted() {
    this.init(); //挂载之后立马加载数据
    this.userinfo = JSON.parse(sessionStorage.getItem("userinfo"));
    //委托vuex采购
    this.$store.dispatch("getnotass");
    // 监听当前路由 解决高亮跟随路由问题
    // console.log(this.$route.path);
    let cutpath = this.$route.path.replace("/menu/", "");
    // console.log(cutpath);
    this.cutpath = cutpath;
  },
  methods: {
    init() {
      //获取菜单数据
      //组合参数
      let man_id = {
        man_id: JSON.parse(sessionStorage.getItem("userinfo")).man_id,
      };
      this.$api.Menu(man_id).then((res) => {
        // console.log(res);
        this.menu = res.data.data;
        // console.log(man_id);
      });
    },
    tab(v) {
      //切换路由
      this.$router.push(v);
    },
    logout() {
      //登出
      //清除存储 跳到登录页面
      sessionStorage.removeItem("userinfo");
      sessionStorage.removeItem("token");
      this.$router.push("/");
    },
  },
};
</script>

<style scoped>
* {
  padding: 0;
  margin: 0;
  list-style: none;
  box-sizing: border-box;
}
.el-header {
  /* width: 100%; */
  background-color: rgb(146, 146, 146);
  height: 5vh !important;
  display: flex;
}

.hl {
  flex: 8;
  height: 100%;
  display: flex;
  align-items: center;
  padding-left: 100px;
  font-size: 20px;
  font-style: italic;
  color: aliceblue;
  font-weight: bold;
}
.hr {
  flex: 1.5;
  display: flex;
  align-items: center;
}
.el-aside {
  background-color: #545c64;
  height: 95vh;
  /* text-align: center; */
}
.el-menu {
  border: none;
}
.content {
  width: 100%;
  height: 100%;
  background: gainsboro;
  padding: 10px;
}
.item {
  width: 100%;
  height: 100%;
  background: white;
  padding: 5px;
}
.items >>> .el-badge__content.is-fixed {
  position: absolute;
  top: 15px !important;
  right: 0 !important;
}
</style>